home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / cdity / ModeProSrc.lha / Prefs / MPPLoadPalette.c < prev    next >
C/C++ Source or Header  |  1997-11-08  |  3KB  |  115 lines

  1. #include "MPP.h"
  2. #include <datatypes/pictureclass.h>
  3.  
  4. extern UBYTE   filename[513];
  5. extern struct FileRequester *PalFileReq;
  6. BOOL SelectPaletteFile(UBYTE *title,UBYTE save,struct Window *Parent);
  7.  
  8. /*
  9. BOOL LoadPalette(struct DefaultNode *DN)
  10. {
  11.   if(SelectPalFile("Open Palette",0))
  12.   {
  13.     return(ReadCMAP(DN,filename));
  14.   }
  15.   return(0);
  16. }
  17. */
  18.  
  19. BOOL ReadCMAP(STRPTR Filename, struct RGB *CReg, ULONG Colors)
  20. {
  21.   struct IFFHandle *iff;
  22.   struct StoredProperty *sp;
  23. //  struct BitMapHeader   *bmhd;
  24.   struct ColorRegister  *cmap;
  25.   LONG l;
  26.   
  27.   LONG error=0,rv; 
  28.  
  29.   rv=0;
  30.  
  31.   if(iff=AllocIFF())
  32.   { 
  33.     if(iff->iff_Stream = Open (Filename,MODE_OLDFILE))
  34.     {
  35.       InitIFFasDOS(iff);
  36.       if(!(error=OpenIFF(iff,IFFF_READ)) )
  37.       {
  38.         if (!(error=PropChunk(iff,ID_ILBM,ID_CMAP)))
  39.         {
  40.           if(!(error=StopOnExit(iff,ID_ILBM,ID_FORM)))           
  41.           {
  42.             if((error=ParseIFF(iff,IFFPARSE_SCAN))>-3)
  43.             {
  44.               if(sp=FindProp(iff,ID_ILBM,ID_CMAP))
  45.               {
  46.                 cmap    =(struct ColorRegister *)sp->sp_Data;
  47.                 Colors  =min(sp->sp_Size/3,Colors);
  48.                 for(l=0;l<Colors;l++)
  49.                 {
  50.                   CReg[l].Red  =cmap[l].red   * 0x01010101;
  51.                   CReg[l].Green=cmap[l].green * 0x01010101;
  52.                   CReg[l].Blue =cmap[l].blue  * 0x01010101;
  53.                 }
  54.                 rv=1;
  55.               }
  56.             }/* end ParseIFF if */        
  57.           }
  58.         } /* End Prop MPPR */
  59.         CloseIFF(iff);
  60.       }
  61.       Close(iff->iff_Stream);
  62.     }
  63.     FreeIFF(iff);
  64.   }
  65.   
  66.   return(rv);
  67. }
  68.  
  69.  
  70. BOOL SaveCMAP(STRPTR Filename, struct RGB *CReg, ULONG Colors)
  71. {
  72.   struct ColorRegister cmap[256];
  73.   struct IFFHandle *iff;   
  74.   ULONG len,l;
  75.   LONG error;
  76.   UWORD font;
  77.   ULONG flags;
  78.   struct DefaultNode *n;
  79.   
  80.   SetIoErr(0);
  81.   
  82.   error=1;
  83.   if(iff=AllocIFF())
  84.   { 
  85.     if(iff->iff_Stream = Open (Filename,MODE_NEWFILE))
  86.     {
  87.       InitIFFasDOS(iff);
  88.       if( !(error=OpenIFF(iff,IFFF_WRITE)) )
  89.       {
  90.         if(!(error=PushChunk(iff,ID_ILBM,ID_FORM, IFFSIZE_UNKNOWN)))
  91.         {
  92.           if(!(error=PushChunk(iff,ID_ILBM,ID_CMAP, Colors * sizeof(cmap[0]))))
  93.           {
  94.             for(l=0;l<Colors;l++)
  95.             {
  96.               cmap[l].red   =CReg[l].Red>>24;
  97.               cmap[l].green =CReg[l].Green>>24;
  98.               cmap[l].blue  =CReg[l].Blue>>24;
  99.             }
  100.             error=WriteChunkBytes(iff,cmap,Colors * sizeof(cmap[0]));
  101.           }
  102.           error|=PopChunk(iff);
  103.         }
  104.         CloseIFF(iff);
  105.       }
  106.       Close(iff->iff_Stream);
  107.     }
  108.     FreeIFF(iff);
  109.   }
  110.   if(error<0)
  111.     return(FALSE);
  112.   else
  113.     return(TRUE);
  114. }
  115.